using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Liya.Crm.Data.Models.Mapping
{
    public class Sys_PermissionMap : EntityTypeConfiguration<Sys_Permission>
    {
        public Sys_PermissionMap()
        {
            // Primary Key
            this.HasKey(t => t.PId);

            // Properties
            this.Property(t => t.PMemo)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Sys_Permission");
            this.Property(t => t.PId).HasColumnName("PId");
            this.Property(t => t.PRoleId).HasColumnName("PRoleId");
            this.Property(t => t.PFunctionId).HasColumnName("PFunctionId");
            this.Property(t => t.PMemo).HasColumnName("PMemo");

            // Relationships
            this.HasOptional(t => t.Sys_Function)
                .WithMany(t => t.Sys_Permission)
                .HasForeignKey(d => d.PFunctionId);
            this.HasOptional(t => t.Sys_Role)
                .WithMany(t => t.Sys_Permission)
                .HasForeignKey(d => d.PRoleId);

        }
    }
}
